package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.AbstractAccount;
import com.acme.bankapp.domain.bank.Account;

public class CheckingAccount extends AbstractAccount implements Account {

	private double overdraft;

	public CheckingAccount(final double amount, final double overdraft) {
		super(amount);
		this.overdraft = overdraft;
	}

	@Override
	public void deposit(final double amount) {
		setBalance(getBalance() + amount);
	}

	@Override
	public void withdraw(final double amount) {
		double balance = getBalance();
		if (balance >= amount) {
			setBalance(balance - amount);
		} else if (this.overdraft > amount - balance) {
			this.overdraft -= (amount - balance);
			setBalance(0);
		}
	}

	@Override
	public double maximumAmountToWithdraw() {
		return getBalance() + this.overdraft;
	}

}
